package service;

import dao.AccountDao;
import entity.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author asus
 */
@Service
public class AccountService {

	@Autowired
	private AccountDao accountDao;

	/**
	 * 转账操作，A账户向B账户转账
	 * 
	 * @param accountA
	 *            A账户号
	 * @param accountB
	 *            B账户号
	 * @param money
	 *            转账金额
	 * @return 转账结果
	 */
	public String moneyTransfer(String accountA, String accountB, double money) {
		System.out.println("开始转账");
		// 获取A和B账户的详情
		Account A = accountDao.selectAccount(accountA);
		Account B = accountDao.selectAccount(accountB);
		// A账户减少相应金额
		accountDao.updateMoney(accountA, A.getMoney() - money);
		// B账户增加相应金额
		accountDao.updateMoney(accountB, B.getMoney() + money);
		return "转账成功";
	}

}
